#!/usr/bin/ruby

require 'ftools'
require 'fileutils'

Base = '/home/hit/OHOS_3.1/Openharmony/out/rk3568'
$Libs_and_exec = Base + '/multimedia/multimedia_usart_standard'
Dynlibs = [
	'libusart_service.z.so',
	'libusart.z.so'
]
Executables = [
	'usart_test' , 'usart_test2' , 'usart_test3'
]
Xml = Base + '/packages/phone/system/profile/usart_service.xml'
Cfg = Base + '/packages/phone/system/etc/init/usart_service.cfg'

out_base = 'output'
def create_dir(dir)
	if File.exists?(dir)
		puts "#{dir} created"
		File.mkdir(dir)
	end
	puts "#{dir} already_exists"
end

`mkdir -p #{out_base + '/lib'}`
`mkdir -p #{out_base + '/xml'}`
`mkdir -p #{out_base + '/bin'}`
`mkdir -p #{out_base + '/cfg'}`
puts "复制 #{Xml}\n    到 #{out_base + '/xml'+'/usart_service.xml'}"
FileUtils.copy(Xml,out_base + '/xml'+'/usart_service.xml')
puts "复制 #{Cfg}\n    到 #{out_base + '/cfg'+'/usart_service.cfg'}"
FileUtils.copy(Cfg,out_base + '/cfg'+'/usart_service.cfg')
Dynlibs.each do |libname|
	puts "复制 #{$Libs_and_exec +'/'+libname }\n    到 #{out_base + '/lib/'+libname}"
	FileUtils.copy($Libs_and_exec +'/'+libname ,out_base + '/lib/'+libname)
end
Executables.each do |exename|
	puts "复制 #{$Libs_and_exec +'/'+exename }\n    到 #{out_base + '/bin/'+exename}"
	FileUtils.copy($Libs_and_exec +'/'+exename ,out_base + '/bin/'+exename)
end
puts "完成"

# ./etc/init/usart_service.cfg:5:                "start usart_service"

# grep: ./bin/usart_test3：匹配到二进制文件
# grep: ./bin/usart_test：匹配到二进制文件
# grep: ./bin/usart_test2：匹配到二进制文件

# ./profile/usart_service.xml:3:    <process>usart_service</process>

# grep: ./lib64/module/multimedia/libusart.z.so：匹配到二进制文件
# grep: ./lib64/libusart_service.z.so：匹配到二进制文件